package com.snake.vargoappstore.loader;

import android.content.Context;

import com.snake.mylibrary.loader.DynamicLoader;
import com.snake.mylibrary.loader.DynamicResult;
import com.snake.mylibrary.net.BaseResult;
import com.snake.mylibrary.net.HttpStatus;
import com.snake.mylibrary.net.OkHttpManager;
import com.snake.vargoappstore.result.ClassFragmentResult;

import org.json.JSONException;
import org.json.JSONObject;


public class ClassFragmentLoader extends DynamicLoader {
    public ClassFragmentLoader(Context context) {
        super(context);
    }

    @Override
    protected DynamicResult createDynamicResult() {
        BaseResult result = OkHttpManager.getInstance()
                .httpGet("http://vstore.vargo.com.cn/pdm_api/download/list?v=1&userAppFlag=1&uid=8a81c2955728e58c015728e58c020000&num=20&page=1&type=1%0A");
        HttpStatus status = result.getStatus();
        if (status != HttpStatus.HTTP_OK) {
            return new ClassFragmentResult(null, status);
        } else {
            JSONObject obj = null;
            try {
                obj = new JSONObject(result.getJson());
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return new ClassFragmentResult(obj, status);
        }

    }
}
